package com.smartpi.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PythonExecuteor {

	public static String executePython(String command) {

		BufferedReader in = null;
		String line;
		StringBuilder value = new StringBuilder();
		Process pr = null;
		try {
			pr = Runtime.getRuntime().exec(command);
			in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
			while ((line = in.readLine()) != null) {
				value.append(line);
			}
			pr.waitFor();
		} catch (Exception e) {
			// TODO: handle exception
			if (pr != null) {
				pr.destroy();
				e.printStackTrace();
			}
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

		}

		return value.toString();

	}

}
